package com.yixiu.study.juc.taobao.num3;

import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.TransferQueue;

/**
 * @CalssName T07_TransferQueue
 * @Description
 * @Author yixiu
 * @Date 2021/6/29 10:24
 * @Verison 1.0
 **/
public class T07_TransferQueue {

    //互相交给对方来打印
    public static void main(String[] args) {
        char[] aI = "1234567".toCharArray();
        char[] aC = "ABCDEFG".toCharArray();

        TransferQueue<Character> queue = new LinkedTransferQueue<Character>();
        new Thread(() -> {
            try {
                for(char c: aI){
                    System.out.println(queue.take());
                    queue.transfer(c);
                }
            } catch (InterruptedException e){
                e.printStackTrace();
            }
        }, "t1").start();

        new Thread(() -> {
            try {
                for(char c: aC){
                    queue.transfer(c);
                    System.out.println(queue.take());

                }
            } catch (InterruptedException e){
                e.printStackTrace();
            }
        }, "t2").start();

    }

}
